<template>
    <div>
        <div><h1>订单详情</h1></div>
        <div>
            <el-divider content-position="left">普通订单</el-divider>
            <el-descriptions title="普通订单">
                <el-descriptions-item label="订单名称">{{
                    orderInfo.prodInfo
                }}</el-descriptions-item>
                <el-descriptions-item label="订单金额">{{
                    orderInfo.orderAmount
                }}</el-descriptions-item>
                <el-descriptions-item label="创建时间">{{
                    orderInfo.createTime
                }}</el-descriptions-item>
                <el-descriptions-item label="订单编号">
                    {{ orderInfo.orderNo }}
                </el-descriptions-item>
                <el-descriptions-item label="订单状态">
                    <el-tag v-if="orderInfo.orderStatus == 0" type="primary"
                        >未支付</el-tag
                    >
                    <el-tag v-if="orderInfo.orderStatus == 1" type="success"
                        >已支付</el-tag
                    >
                    <el-tag v-if="orderInfo.orderStatus == 2">待发货</el-tag>
                </el-descriptions-item>
            </el-descriptions>
        </div>
        <div>
            <el-tabs type="border-card">
                <el-tab-pane label="订单信息">
                    <el-descriptions title="用户信息">
                        <el-descriptions-item label="用户ID">{{
                            user.userId
                        }}</el-descriptions-item>
                        <el-descriptions-item label="用户姓名">{{
                            user.userName
                        }}</el-descriptions-item>
                        <el-descriptions-item label="手机号">{{
                            user.userMobile
                        }}</el-descriptions-item>
                        <el-descriptions-item label="用户邮箱">
                            {{ user.userEmail }}
                        </el-descriptions-item>
                    </el-descriptions>
                </el-tab-pane>
                <el-tab-pane label="商品信息">
                    <el-table :data="detailList" stripe style="width: 100%">
                        <el-table-column prop="prodId" label="商品ID" width="180" />
                        <el-table-column prop="prodName" label="商品名称" width="140" />
                        <el-table-column prop="buyPrice" label="商品价格" width="100" />
                        <el-table-column prop="buyNum" label="购买数量" width="100" />
                        <el-table-column prop="costPrice" label="成本价" width="100" />
                        <el-table-column prop="prodStock" label="库存" width="100" />
                        <el-table-column prop="prodImage" label="图片" width="100">
                            <template #default="scope">
                                <img
                                    :src="scope.row.prodImage"
                                    alt=""
                                    style="width: 50px; height: 50px"
                                />
                            </template>
                        </el-table-column>   
                        <el-table-column prop="amount" label="小计" width="100" />
                        <el-table-column label="操作" />
                    </el-table>
                </el-tab-pane>
                <el-tab-pane label="订单记录">
                    <el-table :data="recordList" stripe style="width: 100%">
                        <el-table-column prop="recordId" label="序号" width="180" />
                        <el-table-column prop="optRecord" label="操作记录" width="140" />
                        <el-table-column prop="createTime" label="操作时间" width="180" />
                    </el-table>
                </el-tab-pane>
                <el-tab-pane label="发货记录">Task</el-tab-pane>
            </el-tabs>
        </div>
    </div>
</template>

<script setup lang="ts">
import { getOrderInfoById } from "@/api/api";
import { onMounted, ref } from "vue";

const orderInfo = ref({
    prodInfo: "",
    orderAmount: 0.0,
    createTime: "",
    orderNo: "",
    orderStatus: 0,
});
const user = ref({
    userId: 0,
    userName: "",
    userMobile: "",
    userEmail: "",
    createTime: "",
});
const detailList = ref([]);
const recordList = ref([]);

// 页面钩子函数
onMounted(() => {
    let orderId = sessionStorage.getItem("orderId");
    getOrderInfoById(orderId).then((res) => {
        orderInfo.value = res.data.data;
        user.value = orderInfo.value.user;
        detailList.value = orderInfo.value.detailList;
        recordList.value = orderInfo.value.recordList;
    });
});
</script>

<style scoped></style>
